const localData = localStorage.getItem('pz_v3pz');

const state = localData ? localData.menu : {
    isCollapse: false,
    selectMenu: [],
    routerList: [],// 路由信息
    menuActive: '1-1'
}

const mutations = {
    collapseMenu(state) {
        state.isCollapse = !state.isCollapse;
        // console.log(state.isCollapse);
    },
    addMenu(state, payload) {
        //去重
        if (state.selectMenu.findIndex(item => item.path === payload.path) === -1) {
            state.selectMenu.push(payload);
        }
        // console.log(state.selectMenu);
    },
    removeMenu(state, index) {
        state.selectMenu.splice(index, 1);
    },
    dynamicMenu(state,payload){
        // 根据glob导入文件
        // console.log(payload,'payload');
        const modules=import.meta.glob('../views/**/**/*.vue');
        // console.log(modules,'modules');
        function routerSet(router){
            router.forEach(route =>{
                if(!route.children){
                    const url=`../views${route.meta.path}/index.vue`;
                    route.component=modules[url];
                }else{
                    routerSet(route.children);
                }
            })
        }
        routerSet(payload);
        state.routerList=payload;
    },
    updateMenuActive(state, payload) {
        state.menuActive = payload;
    }
}

export default {
    state,
    mutations
};